function init() {
  loadFriends();
}
function loadFriends() {
  var req = opensocial.newDataRequest();
  var params = {};
  params[opensocial.DataRequest.PeopleRequestFields.PROFILE_DETAILS] =
        [opensocial.Person.Field.CURRENT_LOCATION];
  
  req.add(req.newFetchPersonRequest(opensocial.DataRequest.PersonId.VIEWER,
		params), 'viewer');
  req.add(req.newFetchPeopleRequest(opensocial.DataRequest.Group.VIEWER_FRIENDS,
		params), 'viewerFriends'); 
  req.send(onLoadFriends);
}

function onLoadFriends(data) {
  var viewer = data.get('viewer').getData();
  var viewerFriends = data.get('viewerFriends').getData();
  var count=0;
  html = new Array();
  html.push('<ul>');
  viewerFriends.each(function(person) {
  alert(person.getId());
  var req2=opensocial.newDataRequest();
  var params2={};
  params2[opensocial.DataRequest.PeopleRequestFields.PROFILE_DETAILS] =
        [opensocial.Person.Field.CURRENT_LOCATION];
 	req2.add(req.newFetchPersonRequest(person.getId(),params2), 'viewer1');
 	req2.send(onLoadCity);	
  });
  }
  function onLoadCity(data) {
  var viewer1 = data.get('viewer1').getData();
  alert(viewer1.getDisplayName());
  var address = viewer1.getField(opensocial.Person.Field.CURRENT_LOCATION);
  alert(address);
  var country = address.getField(opensocial.Address.Field.LOCALITY);
  alert(country);
}
  
